package com.basic.business.operationStoreConfig.service.impl;

import com.basic.business.operationStoreConfig.domain.TOperationStoreConfig;
import com.basic.business.operationStoreConfig.mapper.TOperationStoreConfigMapper;
import com.basic.business.operationStoreConfig.service.ITOperationStoreConfigService;
import com.basic.business.store.mapper.TStoreMgmtMapper;
import com.basic.business.store.vo.StoreSimpleDetailRespVo;
import com.basic.common.core.service.impl.BaseServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * 运营店铺配置Service业务层处理
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TOperationStoreConfigServiceImpl extends BaseServiceImpl<TOperationStoreConfigMapper, TOperationStoreConfig> implements ITOperationStoreConfigService {

    @Resource
    private TOperationStoreConfigMapper operationStoreConfigMapper;

    @Resource
    private TStoreMgmtMapper tStoreMgmtMapper;

    @Override
    public TOperationStoreConfig getConfigByTypeAndAncestors(Integer configType, Long deptId, String ancestors) {
        return operationStoreConfigMapper.getConfigByTypeAndAncestors(configType, deptId, ancestors);
    }

    @Override
    public List<StoreSimpleDetailRespVo> getStoreSimpleDetailList(Integer configType, Long deptId, String ancestors) {
        List<StoreSimpleDetailRespVo> list=null;
        TOperationStoreConfig config = operationStoreConfigMapper.getConfigByTypeAndAncestors(configType, deptId, ancestors);
        if (config != null){
            String configStore = config.getConfigStore();
            if (Strings.isNotBlank(configStore)){
                String[] split = configStore.split(",");
                List<String> storeIds = Arrays.asList(split);

                list = tStoreMgmtMapper.getStoreSimpleDetailList(storeIds);
            }
        }
        return list==null? Collections.emptyList():list;
    }
}
